#include <iostream>
#include <string.h>

using namespace std;

char a[105][105];
int dx[8] = {1,0,-1,0};
int dy[8] = {0,1,0,-1};
int vis[105][105];
int ans = 0;
int n,m;

void dfs(int x,int y){
    if(vis[x][y]){
        return;
    }
    else{
        vis[x][y] = 1;
        for(int i = 0; i < 4; i++){
            int xx = x+dx[i];
            int yy = y+dy[i];
            if(xx >= 1 && yy >= 1 && xx <= n && yy <= m && a[xx][yy] != '0'){
                dfs(xx,yy);
            }
        }
    }
}

int main() {
    cin >> n >> m;
    memset(a,0,sizeof(a));
    memset(vis,0,sizeof(vis));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] != '0' && !vis[i][j]){
                ans++;
                dfs(i,j);
            }
        }
    }
    cout << ans;
}